package com.example.luke.cashorderingsystem.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;
import android.widget.DatePicker;
import android.widget.TextView;

import com.example.luke.cashorderingsystem.R;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by luke on 12/12/2016.
 */

public class DateRangePickerDialog extends Dialog {

    @InjectView(R.id.start_date)DatePicker startDate;
    @InjectView(R.id.end_date)DatePicker endDate;


    public interface DateListener{

        void getDate(String startDate, String endDate);

    }
    DateListener dateListener;

    public void setDateListener(DateListener dateListener) {
        this.dateListener = dateListener;
    }

    public DateRangePickerDialog(Context context){

        super(context);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);


        setContentView(R.layout.date_range_picker_dialog);

        ButterKnife.inject(this);

    }

    @OnClick(R.id.close)
    void  close(){

        dismiss();

    }
    @OnClick(R.id.search)
    void search(){

        String tempStartDate=startDate.getYear()+"."+(startDate.getMonth()+1)+"."+startDate.getDayOfMonth();

        String tempReturnDate=endDate.getYear()+"."+(endDate.getMonth()+1)+"."+endDate.getDayOfMonth();



        if (dateListener!=null)
            dateListener.getDate(tempStartDate,tempReturnDate);

        dismiss();

    }
//    public static java.util.Date getDateFromDatePicker(DatePicker datePicker){
//        int day = datePicker.getDayOfMonth();
//        int month = datePicker.getMonth();
//        int year =  datePicker.getYear();
//
//        Calendar calendar = Calendar.getInstance();
//        calendar.set(year, month, day);
//
//        return calendar.getTime();
//    }

}
